from fastapi import APIRouter

from core.role_core import create_role_info, get_role_info, update_role_info, delete_role_info
from core.user_core import create_user_info, get_user_by_id, get_user_list, update_user_info, delete_user_by_id
from entity.schema.role_schema import RoleCreate
from entity.schema.user_schema import UserOut, UserCreate, UserUpdate
from exception.custom_exception import CustomErrorThrowException
from utils.base_response import BaseResponse
role = APIRouter()


@role.post("/add")
async def create_role(role: RoleCreate):
    #创建角色

    role = await create_role_info(role.name, role.desc)
    return BaseResponse(code=200, msg="success", data=None)

@role.get("/get/{role_id}")
async def get_role(role_id: int):
    #获取角色和信息

    role = await get_role_info(role_id)
    return BaseResponse(code=200, msg="success", data=role)

@role.put("/update/{role_id}")
async def update_role(role_id: int, role: RoleCreate):
    #修改对应id角色

    await update_role_info(role_id, role)
    return BaseResponse(code=200, msg="success", data=None)

@role.delete("/del/{role_id}")
async def delete_role(role_id: int):
    #删除对应id角色

    await delete_role_info(role_id)
    return BaseResponse(code=200, msg="success", data=None)